home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / dp / dp.lha / dp_main.s < prev    next >
Encoding:
Text File  |  1996-10-18  |  10.4 KB  |  678 lines

  1. ;
  2. ; Double-precision math interface library for ACE.
  3. ;
  4. ; Register a6 is preserved and restored by each routine
  5. ; since Sozobon C uses this as a link register.
  6. ; Author: David J Benn
  7. ;   Date: 11th February 1996,
  8. ;      16th August 1996,
  9. ;      29th September 1996,
  10. ;      1st,18th October 1996
  11. ;
  12.  
  13. TRUE    equ    -1
  14. FALSE    equ    0
  15.  
  16.     ; Basic functions.
  17.     xref    _LVOIEEEDPAbs
  18.     xref    _LVOIEEEDPAdd
  19.     xref    _LVOIEEEDPCeil
  20.     xref    _LVOIEEEDPCmp
  21.     xref    _LVOIEEEDPDiv
  22.     xref    _LVOIEEEDPFix
  23.     xref    _LVOIEEEDPFloor
  24.     xref    _LVOIEEEDPFlt
  25.     xref    _LVOIEEEDPMul
  26.     xref    _LVOIEEEDPNeg
  27.     xref    _LVOIEEEDPSub
  28.     xref    _LVOIEEEDPTst
  29.  
  30.     ; Transcendental functions.
  31.     xref    _LVOIEEEDPAsin
  32.     xref    _LVOIEEEDPAcos
  33.     xref    _LVOIEEEDPAtan
  34.     xref    _LVOIEEEDPSin
  35.     xref    _LVOIEEEDPCos
  36.     xref    _LVOIEEEDPTan
  37.     xref    _LVOIEEEDPSincos
  38.     xref    _LVOIEEEDPSinh
  39.     xref    _LVOIEEEDPCosh
  40.     xref    _LVOIEEEDPTanh
  41.     xref    _LVOIEEEDPExp
  42.     xref    _LVOIEEEDPFieee
  43.     xref    _LVOIEEEDPLog
  44.     xref    _LVOIEEEDPLog10
  45.     xref    _LVOIEEEDPPow
  46.     xref    _LVOIEEEDPSqrt
  47.     xref    _LVOIEEEDPTieee
  48.  
  49.     ; Miscellaneous external references.
  50.     xref    _AbsExecBase
  51.     xref    _LVOOpenLibrary
  52.     xref    _LVOCloseLibrary
  53.  
  54.     xref    _MathTransBase
  55.     xref    _LVOSPFieee    
  56.     xref    _LVOSPTieee    
  57.  
  58.     ; Exports.
  59.     xdef    _MathIeeeDoubBasBase
  60.     xdef    _MathIeeeDoubTransBase
  61.  
  62.     section    code, dp_code
  63.  
  64. ;************************************
  65.  
  66.     PUBLIC    _dp_open
  67.     ;
  68.     ; Open IEEE DP libraries x 2.
  69.     ;
  70. _dp_open:
  71.     move.l    a6,_a6
  72.  
  73.     movea.l _AbsExecBase,a6        
  74.  
  75.     ; Open basic library.
  76.     movea.l    #_ieeedoubbaslibname,a1
  77.     move.l    #34,d0
  78.     jsr     _LVOOpenLibrary(a6)
  79.     tst.l    d0
  80.     beq.s    _abort_dp_open
  81.     move.l    d0,_MathIeeeDoubBasBase
  82.  
  83.     ; Open transcendental library.
  84.     movea.l    #_ieeedoubtranslibname,a1
  85.     move.l    #34,d0
  86.     jsr     _LVOOpenLibrary(a6)
  87.     tst.l    d0
  88.     beq.s    _abort_dp_open
  89.     move.l    d0,_MathIeeeDoubTransBase
  90.     
  91.     ; Exit with success code (TRUE).
  92.     move.l    #TRUE,d0    ; okay.
  93.     bra.s    _exit_dp_open
  94.  
  95. _abort_dp_open:
  96.     move.l    #FALSE,d0    ; error.
  97.  
  98. _exit_dp_open:
  99.     movea.l    _a6,a6
  100.     
  101.     rts
  102.  
  103. ;************************************
  104.  
  105.     PUBLIC    _dp_close
  106.     ;
  107.     ; Close IEEE DP libraries x 2.
  108.     ;
  109. _dp_close:
  110.     move.l    a6,_a6
  111.  
  112.     tst.l    _MathIeeeDoubBasBase
  113.     beq.s    _exit_dp_close
  114.  
  115.     movea.l _AbsExecBase,a6
  116.  
  117.     move.l  _MathIeeeDoubBasBase,a1
  118.     jsr     _LVOCloseLibrary(a6)
  119.  
  120.     tst.l    _MathIeeeDoubTransBase
  121.     beq.s    _exit_dp_close
  122.  
  123.     move.l  _MathIeeeDoubTransBase,a1
  124.     jsr     _LVOCloseLibrary(a6)
  125.  
  126. _exit_dp_close:
  127.     movea.l    _a6,a6
  128.     
  129.     rts
  130.  
  131. ;************************************
  132.  
  133.     PUBLIC    _dp_longint_to_double
  134.     ;
  135.     ; Convert LONGINT to DOUBLE.
  136.     ;
  137. _dp_longint_to_double:
  138.     move.l    a6,_a6
  139.  
  140.     move.l    8(sp),d0        ; integer value.
  141.  
  142.     movea.l    _MathIeeeDoubBasBase,a6
  143.     jsr    _LVOIEEEDPFlt(a6)
  144.  
  145.     move.l    4(sp),a0        ; address of double result.
  146.     move.l    d0,(a0)+
  147.     move.l    d1,(a0)
  148.  
  149.     movea.l    _a6,a6
  150.     
  151.     rts
  152.  
  153. ;************************************
  154.  
  155.     PUBLIC    _dp_double_to_longint
  156.     ;
  157.     ; Convert DOUBLE to LONGINT.
  158.     ;
  159. _dp_double_to_longint:
  160.     move.l    a6,_a6
  161.  
  162.     move.l    8(sp),a1        ; address of double.
  163.     
  164.     move.l    (a1)+,d0
  165.     move.l    (a1),d1
  166.  
  167.     movea.l    _MathIeeeDoubBasBase,a6
  168.     jsr    _LVOIEEEDPFix(a6)
  169.  
  170.     move.l    4(sp),a0        ; address of integer result.
  171.     move.l    d0,(a0)
  172.  
  173.     movea.l    _a6,a6
  174.  
  175.     rts
  176.  
  177. ;************************************
  178.  
  179.     PUBLIC    _dp_single_to_double
  180.     ;
  181.     ; Convert SINGLE to DOUBLE.
  182.     ;
  183. _dp_single_to_double:
  184.     move.l    a6,_a6
  185.  
  186.     move.l    8(sp),d0        ; single value.
  187.  
  188.     movea.l    _MathTransBase,a6
  189.     jsr    _LVOSPTieee(a6)        ; FFP -> IEEE SP
  190.     movea.l    _MathIeeeDoubTransBase,a6    
  191.     jsr    _LVOIEEEDPFieee(a6)    ; IEEE SP -> IEEE DP
  192.  
  193.     move.l    4(sp),a0        ; address of double result.
  194.     move.l    d0,(a0)+
  195.     move.l    d1,(a0)
  196.  
  197.     movea.l    _a6,a6
  198.     
  199.     rts
  200.  
  201. ;************************************
  202.  
  203.     PUBLIC    _dp_double_to_single
  204.     ;
  205.     ; Convert DOUBLE to SINGLE.
  206.     ;
  207. _dp_double_to_single:
  208.     move.l    a6,_a6
  209.  
  210.     move.l    8(sp),a1        ; address of double.
  211.  
  212.     move.l    (a1)+,d0
  213.     move.l    (a1),d1
  214.  
  215.     movea.l    _MathIeeeDoubTransBase,a6
  216.     jsr    _LVOIEEEDPTieee(a6)    ; IEEE DP -> IEEE SP
  217.     movea.l    _MathTransBase,a6
  218.     jsr    _LVOSPFieee(a6)        ; IEEE SP -> FFP
  219.  
  220.     move.l    4(sp),a0        ; address of single result.
  221.     move.l    d0,(a0)
  222.  
  223.     movea.l    _a6,a6
  224.  
  225.     rts
  226.  
  227. ;************************************
  228.  
  229.     PUBLIC    _dp_add
  230.     ;
  231.     ; Add two DOUBLE values (result = op1 + op2).
  232.     ;
  233. _dp_add:
  234.     move.l    a6,_a6
  235.  
  236.     move.l    12(sp),a2        ; address of operand 2.
  237.     move.l    8(sp),a1        ; address of operand 1.
  238.  
  239.     move.l    (a2)+,d2
  240.     move.l    (a2),d3            
  241.  
  242.     move.l    (a1)+,d0
  243.     move.l    (a1),d1    
  244.  
  245.     movea.l    _MathIeeeDoubBasBase,a6
  246.     jsr    _LVOIEEEDPAdd(a6)
  247.  
  248.     move.l    4(sp),a0        ; address of result.    
  249.     move.l    d0,(a0)+
  250.     move.l    d1,(a0)
  251.  
  252.     movea.l    _a6,a6
  253.  
  254.     rts
  255.  
  256. ;************************************
  257.  
  258.     PUBLIC    _dp_sub
  259.     ;
  260.     ; Subtract two DOUBLE values (result = op1 - op2).
  261.     ;
  262. _dp_sub:
  263.     move.l    a6,_a6
  264.  
  265.     move.l    12(sp),a2        ; address of operand 2.
  266.     move.l    8(sp),a1        ; address of operand 1.
  267.  
  268.     move.l    (a2)+,d2
  269.     move.l    (a2),d3            
  270.  
  271.     move.l    (a1)+,d0
  272.     move.l    (a1),d1    
  273.  
  274.     movea.l    _MathIeeeDoubBasBase,a6
  275.     jsr    _LVOIEEEDPSub(a6)
  276.  
  277.     move.l    4(sp),a0        ; address of result.    
  278.     move.l    d0,(a0)+
  279.     move.l    d1,(a0)
  280.  
  281.     movea.l    _a6,a6
  282.  
  283.     rts
  284.  
  285. ;************************************
  286.  
  287.     PUBLIC    _dp_mul
  288.     ;
  289.     ; Mulitply two DOUBLE values (result = op1 * op2).
  290.     ;
  291. _dp_mul:
  292.     move.l    a6,_a6
  293.  
  294.     move.l    12(sp),a2        ; address of operand 2.
  295.     move.l    8(sp),a1        ; address of operand 1.
  296.  
  297.     move.l    (a2)+,d2
  298.     move.l    (a2),d3            
  299.  
  300.     move.l    (a1)+,d0
  301.     move.l    (a1),d1    
  302.  
  303.     movea.l    _MathIeeeDoubBasBase,a6
  304.     jsr    _LVOIEEEDPMul(a6)
  305.  
  306.     move.l    4(sp),a0        ; address of result.    
  307.     move.l    d0,(a0)+
  308.     move.l    d1,(a0)
  309.  
  310.     movea.l    _a6,a6
  311.  
  312.     rts
  313.  
  314. ;************************************
  315.  
  316.     PUBLIC    _dp_div
  317.     ;
  318.     ; Divide two DOUBLE values (result = op1 / op2).
  319.     ;
  320. _dp_div:
  321.     move.l    a6,_a6
  322.  
  323.     move.l    12(sp),a2        ; address of operand 2.
  324.     move.l    8(sp),a1        ; address of operand 1.
  325.  
  326.     move.l    (a2)+,d2
  327.     move.l    (a2),d3            
  328.  
  329.     move.l    (a1)+,d0
  330.     move.l    (a1),d1    
  331.  
  332.     movea.l    _MathIeeeDoubBasBase,a6
  333.     jsr    _LVOIEEEDPDiv(a6)
  334.  
  335.     move.l    4(sp),a0        ; address of result.    
  336.     move.l    d0,(a0)+
  337.     move.l    d1,(a0)
  338.  
  339.     movea.l    _a6,a6
  340.  
  341.     rts
  342.  
  343. ;************************************
  344.  
  345.     PUBLIC    _dp_cmp
  346.     ;
  347.     ; Compare two DOUBLE values.
  348.     ; Returns an integer:
  349.     ; 
  350.     ;     +1 if op1 > op2
  351.     ;     -1 if op1 < op2
  352.     ;      0 if op1 = op2
  353.     ;
  354. _dp_cmp:
  355.     move.l    a6,_a6
  356.  
  357.     move.l    12(sp),a2        ; address of operand 2.
  358.     move.l    8(sp),a1        ; address of operand 1.
  359.  
  360.     move.l    (a2)+,d2
  361.     move.l    (a2),d3            
  362.  
  363.     move.l    (a1)+,d0
  364.     move.l    (a1),d1    
  365.  
  366.     movea.l    _MathIeeeDoubBasBase,a6
  367.     jsr    _LVOIEEEDPCmp(a6)
  368.  
  369.     move.l    4(sp),a0        ; address of result.    
  370.     move.l    d0,(a0)
  371.  
  372.     movea.l    _a6,a6
  373.  
  374.     rts
  375.  
  376. ;************************************
  377.  
  378.     PUBLIC    _dp_pow
  379.     ;
  380.     ; Raise one DOUBLE to the power of another.
  381.     ; (result = op1 ^ op2).
  382.     ;
  383. _dp_pow:
  384.     move.l    a6,_a6
  385.  
  386.     move.l    12(sp),a2        ; address of operand 2.
  387.     move.l    8(sp),a1        ; address of operand 1.
  388.  
  389.     move.l    (a1)+,d0
  390.     move.l    (a1),d1        
  391.  
  392.     move.l    (a2)+,d2
  393.     move.l    (a2),d3
  394.  
  395.     movea.l    _MathIeeeDoubTransBase,a6
  396.     jsr    _LVOIEEEDPPow(a6)
  397.  
  398.     move.l    4(sp),a0        ; address of result.    
  399.     move.l    d0,(a0)+
  400.     move.l    d1,(a0)
  401.  
  402.     movea.l    _a6,a6
  403.  
  404.     rts
  405.  
  406. ;************************************
  407.  
  408.     PUBLIC    _dp_abs
  409.     ;
  410.     ; Return the absolute value of a DOUBLE.
  411.     ;
  412. _dp_abs:
  413.     move.l    a6,_a6
  414.  
  415.     move.l    8(sp),a1        ; address of operand.
  416.  
  417.     move.l    (a1)+,d0
  418.     move.l    (a1),d1    
  419.  
  420.     movea.l    _MathIeeeDoubBasBase,a6
  421.     jsr    _LVOIEEEDPAbs(a6)
  422.  
  423.     move.l    4(sp),a0        ; address of result.    
  424.     move.l    d0,(a0)+
  425.     move.l    d1,(a0)
  426.  
  427.     movea.l    _a6,a6
  428.  
  429.     rts
  430.  
  431. ;************************************
  432.  
  433.     PUBLIC    _dp_neg
  434.     ;
  435.     ; Return the negated value of a DOUBLE.
  436.     ;
  437. _dp_neg:
  438.     move.l    a6,_a6
  439.  
  440.     move.l    8(sp),a1        ; address of operand.
  441.  
  442.     move.l    (a1)+,d0
  443.     move.l    (a1),d1    
  444.  
  445.     movea.l    _MathIeeeDoubBasBase,a6
  446.     jsr    _LVOIEEEDPNeg(a6)
  447.  
  448.     move.l    4(sp),a0        ; address of result.    
  449.     move.l    d0,(a0)+
  450.     move.l    d1,(a0)
  451.  
  452.     movea.l    _a6,a6
  453.  
  454.     rts
  455.  
  456. ;************************************
  457.  
  458.     PUBLIC    _dp_ceil
  459.     ;
  460.     ; Return the least integer which is >= a DOUBLE.
  461.     ; Result is DOUBLE not LONGINT!
  462.     ;
  463. _dp_ceil:
  464.     move.l    a6,_a6
  465.  
  466.     move.l    8(sp),a1        ; address of operand.
  467.  
  468.     move.l    (a1)+,d0
  469.     move.l    (a1),d1    
  470.  
  471.     movea.l    _MathIeeeDoubBasBase,a6
  472.     jsr    _LVOIEEEDPCeil(a6)
  473.  
  474.     move.l    4(sp),a0        ; address of result.    
  475.     move.l    d0,(a0)+
  476.     move.l    d1,(a0)
  477.  
  478.     movea.l    _a6,a6
  479.  
  480.     rts
  481.  
  482. ;************************************
  483.  
  484.     PUBLIC    _dp_floor
  485.     ;
  486.     ; Return the largest integer which is <= a DOUBLE.
  487.     ; Result is DOUBLE not LONGINT!
  488.     ;
  489. _dp_floor:
  490.     move.l    a6,_a6
  491.  
  492.     move.l    8(sp),a1        ; address of operand.
  493.  
  494.     move.l    (a1)+,d0
  495.     move.l    (a1),d1    
  496.  
  497.     movea.l    _MathIeeeDoubBasBase,a6
  498.     jsr    _LVOIEEEDPFloor(a6)
  499.  
  500.     move.l    4(sp),a0        ; address of result.    
  501.     move.l    d0,(a0)+
  502.     move.l    d1,(a0)
  503.  
  504.     movea.l    _a6,a6
  505.  
  506.     rts
  507.  
  508. ;************************************
  509.  
  510.     PUBLIC    _dp_sin
  511.     ;
  512.     ; Return the sine of a DOUBLE (radians).
  513.     ;
  514. _dp_sin:
  515.     move.l    a6,_a6
  516.  
  517.     move.l    8(sp),a1        ; address of operand.
  518.  
  519.     move.l    (a1)+,d0
  520.     move.l    (a1),d1    
  521.  
  522.     movea.l    _MathIeeeDoubTransBase,a6
  523.     jsr    _LVOIEEEDPSin(a6)
  524.  
  525.     move.l    4(sp),a0        ; address of result.    
  526.     move.l    d0,(a0)+
  527.     move.l    d1,(a0)
  528.  
  529.     movea.l    _a6,a6
  530.  
  531.     rts
  532.  
  533. ;************************************
  534.  
  535.     PUBLIC    _dp_cos
  536.     ;
  537.     ; Return the cosine of a DOUBLE (radians).
  538.     ;
  539. _dp_cos:
  540.     move.l    a6,_a6
  541.  
  542.     move.l    8(sp),a1        ; address of operand.
  543.  
  544.     move.l    (a1)+,d0
  545.     move.l    (a1),d1    
  546.  
  547.     movea.l    _MathIeeeDoubTransBase,a6
  548.     jsr    _LVOIEEEDPCos(a6)
  549.  
  550.     move.l    4(sp),a0        ; address of result.    
  551.     move.l    d0,(a0)+
  552.     move.l    d1,(a0)
  553.  
  554.     movea.l    _a6,a6
  555.  
  556.     rts
  557.  
  558. ;************************************
  559.  
  560.     PUBLIC    _dp_tan
  561.     ;
  562.     ; Return the tangent of a DOUBLE (radians).
  563.     ;
  564. _dp_tan:
  565.     move.l    a6,_a6
  566.  
  567.     move.l    8(sp),a1        ; address of operand.
  568.  
  569.     move.l    (a1)+,d0
  570.     move.l    (a1),d1    
  571.  
  572.     movea.l    _MathIeeeDoubTransBase,a6
  573.     jsr    _LVOIEEEDPTan(a6)
  574.  
  575.     move.l    4(sp),a0        ; address of result.    
  576.     move.l    d0,(a0)+
  577.     move.l    d1,(a0)
  578.  
  579.     movea.l    _a6,a6
  580.  
  581.     rts
  582.  
  583. ;************************************
  584.  
  585.     PUBLIC    _dp_exp
  586.     ;
  587.     ; Return e to the power of a DOUBLE.
  588.     ;
  589. _dp_exp:
  590.     move.l    a6,_a6
  591.  
  592.     move.l    8(sp),a1        ; address of operand.
  593.  
  594.     move.l    (a1)+,d0
  595.     move.l    (a1),d1    
  596.  
  597.     movea.l    _MathIeeeDoubTransBase,a6
  598.     jsr    _LVOIEEEDPExp(a6)
  599.  
  600.     move.l    4(sp),a0        ; address of result.    
  601.     move.l    d0,(a0)+
  602.     move.l    d1,(a0)
  603.  
  604.     movea.l    _a6,a6
  605.  
  606.     rts
  607.  
  608. ;************************************
  609.  
  610.     PUBLIC    _dp_log
  611.     ;
  612.     ; Return the natural logarithm (base e) of a DOUBLE.
  613.     ;
  614. _dp_log:
  615.     move.l    a6,_a6
  616.  
  617.     move.l    8(sp),a1        ; address of operand.
  618.  
  619.     move.l    (a1)+,d0
  620.     move.l    (a1),d1    
  621.  
  622.     movea.l    _MathIeeeDoubTransBase,a6
  623.     jsr    _LVOIEEEDPLog(a6)
  624.  
  625.     move.l    4(sp),a0        ; address of result.    
  626.     move.l    d0,(a0)+
  627.     move.l    d1,(a0)
  628.  
  629.     movea.l    _a6,a6
  630.  
  631.     rts
  632.  
  633. ;************************************
  634.  
  635.     PUBLIC    _dp_sqrt
  636.     ;
  637.     ; Return the square root of a DOUBLE.
  638.     ;
  639. _dp_sqrt:
  640.     move.l    a6,_a6
  641.  
  642.     move.l    8(sp),a1        ; address of operand.
  643.  
  644.     move.l    (a1)+,d0
  645.     move.l    (a1),d1    
  646.  
  647.     movea.l    _MathIeeeDoubTransBase,a6
  648.     jsr    _LVOIEEEDPSqrt(a6)
  649.  
  650.     move.l    4(sp),a0        ; address of result.    
  651.     move.l    d0,(a0)+
  652.     move.l    d1,(a0)
  653.  
  654.     movea.l    _a6,a6
  655.  
  656.     rts
  657.  
  658. ;************************************
  659.         
  660.     section    data, dp_data
  661.  
  662. _ieeedoubbaslibname:    dc.b    'mathieeedoubbas.library',0
  663. _ieeedoubtranslibname:    dc.b    'mathieeedoubtrans.library',0
  664.  
  665. _MathIeeeDoubBasBase:    dc.l     0
  666. _MathIeeeDoubTransBase:    dc.l     0
  667.  
  668. ;************************************
  669.  
  670.     section bss, dp_bss
  671.  
  672. _a6:            ds.l 1
  673.  
  674. ;************************************
  675.  
  676.     END
  677.